package silentDonkey.web.servlet;

import silentDonkey.service.UserService;
import silentDonkey.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.獲取要刪除的User id
        String id = request.getParameter("id");
        // 2.調用service刪除
        UserService service = new UserServiceImpl();
        service.deleteUser(id);
        // 3.跳轉到查詢所有Servlet頁面（ListUserServlet）
//        request.getRequestDispatcher("/listUserServlet").forward(request, response);
        response.sendRedirect(request.getContextPath() + "/listUserServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
